package cn.tedu.property_management_system.controller;


import cn.tedu.property_management_system.entity.Building;
import cn.tedu.property_management_system.entity.House;

import cn.tedu.property_management_system.service.IHouseService;
import cn.tedu.property_management_system.utils.JsonPage;
import cn.tedu.property_management_system.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/house")
public class HouseController {
    @Autowired
    IHouseService service;

    @GetMapping("/search/select/{room}")
    public List<House> search(@PathVariable("room") String room) {
        log.debug(room+"");

        return service.search(room);
    }

    @RequestMapping("/search/select/list")
    public List<House> selectList() {
        return service.selectList();
    }

    @RequestMapping("/add/insert")
    public int insertUser(@RequestBody House house) {
        return service.insertUser(house);
    }


    @RequestMapping("/edit/select")
    public House selectUser(@RequestBody House house) {

        return service.selectUser(house);
    }

    @RequestMapping("/edit/update")
    public void update(@RequestBody House house) {
        service.update(house);

    }


    @RequestMapping("/user/delete")
    public void delete(@RequestBody House house) {

        service.delete(house);

    }

    @RequestMapping("/users/delete")
    public int deletes(@RequestBody List<House> list) {
     return    service.deletes(list);
    }

    @GetMapping("/get/rooms")
    public JsonResult<List<String>> getrooms(){
        List<String> rooms=service.getHouseRoom();
        return JsonResult.OK(rooms);
    }


    @GetMapping("/get/page/{pageSize}/{pageIndex}")
    public JsonPage<House> getPage(@PathVariable("pageSize") Integer pageSize, @PathVariable("pageIndex") Integer pageIndex) {
        log.debug(pageSize+"-----"+pageIndex);
        JsonPage<House> buildingJsonPage = service.pageSelect(pageSize, pageIndex);
        return buildingJsonPage;
    }

}
